package top.jamsee.handler;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import top.jamsee.exception.NameException;

@ControllerAdvice
public class GlobalException {

    @ExceptionHandler(value = NameException.class)
    public ModelAndView userExceptionHandler(Exception exception){
        ModelAndView mv=new ModelAndView();
        mv.setViewName("view/error");
        mv.addObject("ex",exception);
        mv.addObject("msg","exception");
        System.out.println(exception);
        return mv;
    }
    //默认的异常
    @ExceptionHandler
    public ModelAndView defaultExceptionHandler(Exception exception){
        ModelAndView mv=new ModelAndView();
        mv.setViewName("view/error");
        mv.addObject("msg","开开心心");
        mv.addObject("ex",exception);
        System.out.println(exception);
        return mv;
    }



}
